from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST


class AddKnowlegePage(BasePage):
    # 添加应收款页面url
    url='http://{}/crm/index.php?m=knowledge&a=add'.format(HOST)
    # 定位标题
    knowledge_title_locator = (By.ID, 'title')
    # 定位保存按钮
    knowledge_save_loactor = (By.CSS_SELECTOR, 'body > div.container > div.row > div > form > table > tfoot > tr > td > input:nth-child(1)')
    # 定位知识添加成功提示语
    knowlege_success_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')

    def input_knowlege_title(self,title):
        '''输入标题'''
        self.driver.find_element(*self.knowledge_title_locator).send_keys(title)

    def click_add_knowlege_save(self):
        '''点击保存'''
        self.driver.find_element(*self.knowledge_save_loactor).click()

    def get_add_knowlege_url(self):
        '''获取知识页面url'''
        return self.current_url()

    def get_knowlege_success_tips(self):
        '''获取知识添加成功提示语'''
        knowlege_tips=self.driver.find_element(*self.knowlege_success_tips_locator).text
        return knowlege_tips